package top.hugo.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.Map;

/**
 * @Title: DataBaseMapper
 * @Description:
 * @Auther: kuanghua
 * @create 2022/6/3 8:38
 */
public interface DataBaseMapper {

    /**
     * mysql获取所有表
     *
     * @param dbName
     * @return
     */
    @Select("SELECT  table_schema as tableSchema ,table_name as tableName,table_comment as tableComment,create_time as createTime,update_time as updateTime " +
            "FROM  information_schema.tables WHERE TABLE_SCHEMA = #{dbName}")
    ArrayList<Map> getAllTableFromDb(@Param("dbName") String dbName);


    /**
     * mysql获取表所有字段信息
     *
     * @param tbName
     * @return
     */
    @Select("SELECT table_schema as tableSchema,table_name as tableName,column_name as columnName,is_nullable as isNullable," +
            "data_type as dataType,column_type as columnType,column_key as columnKey,extra,column_comment as columnComment" +
            "FROM INFORMATION_SCHEMA.COLUMNS COL Where TABLE_SCHEMA=#{dbName} AND  COL.TABLE_NAME=#{tbName}")
    ArrayList<Map> getAllColumnFromTb(@Param("dbName") String dbName, @Param("tbName") String tbName);
}
